<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
        <title>游记明细</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travelContent.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/checkLogin.js"></script>
    
    <script>
        $(function () {
            //游记的id
            var params=getParams();
            var travelContentId=params.id
            var flag;  //标记是否已经点过赞

            //获取游记id
            if (params.id) {
                $.get(baseUrl + "/travels/" + params.id,function (data) {
                    $(".travels").renderValues(data);
                })
            }

            //刚进来就查询点赞人数并设置到图标
            $.get(baseUrl+"/great/getCountByTravelContentId/"+travelContentId,function (data) {
                console.log(data);
                $("#totalCount").html(data.count);
            })

            //回显点赞
            $.get(baseUrl+"/great/selectByUserIdAndTravelContentId/"+travelContentId+"/"+user.id,function (data) {
                //已经点过赞
                console.log(data);
                if(data.success){
                    $("#likeBtn").removeClass().addClass("fa fa-thumbs-up").html("取消点赞");
                    flag=false; //点过赞的
                }else{
                    //没有点过赞
                    $("#likeBtn").removeClass().addClass("fa fa-thumbs-o-up");
                    flag=true;  //没有点过赞的
                }
            })

            //点赞按钮绑定点击事件
                //如果点过赞说明点击后会进行对象的删除
                //如果没有点过赞说明点击后会进行对象的添加
                $("#likeBtn").click(function () {
                    if(flag){
                        $.post(baseUrl+"/great/"+travelContentId+"/"+user.id,function (data) {
                            if(data.success){
                                alert("爱你不是因为你的美丽");
                                $("#likeBtn").removeClass().addClass("fa fa-thumbs-up").html("取消点赞");
                                $.get(baseUrl+"/great/getCountByTravelContentId/"+travelContentId,function (data) {
                                    console.log(data);
                                    $("#totalCount").html(data.count);
                                })
                            }
                            flag=false;
                        })
                    }else{
                        $.post(baseUrl+"/great/deleteRelation/"+travelContentId+"/"+user.id,function (data) {
                            if(data.success){
                                alert("分手快乐祝你快乐");
                                $("#likeBtn").removeClass().addClass("fa fa-thumbs-o-up").html("点赞");
                                $.get(baseUrl+"/great/getCountByTravelContentId/"+travelContentId,function (data) {
                                    console.log(data);
                                    $("#totalCount").html(data.count);
                                })
                            }
                            flag=true;
                        })
                    }
                })
        })
    </script>
    
</head>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
        </div>
    </div>
</div>

<div class="travels">
    <img  class="cover" render-src="coverUrl">
    <div class="container">
        <h6 class="title" render-html="title" ></h6>
        <small>
            <span render-html="lastUpdateTime"></span>
            浏览 <span> 0</span>
            回复 <span> 0</span>
        </small>
        <div class="row">
            <div class="col-2 img">
                <img  class="rounded-circle" render-src="author.headImgUrl">
            </div>
            <div class="col-6 mine">
                <small>
                    <span render-html="author.nickName"></span>
                    <button class="btn" id="followBtn">关注</button>
                    <br>
                    <span>0 </span>篇游记
                    <span>0 </span>粉丝
                </small>
            </div>
            <div class="attention col">
                <span class="addr" render-html="place.name"></span>
            </div>
        </div>
    </div>
    ,
    <div class="container">
        <fieldset>
            <legend>我的出行信息</legend>
            <div class="d-flex">
                <div class="p-2  flex-fill">
                    <i class="fa fa-calendar"></i> 出发时间 <span render-html="travelTime"></span>
                </div>
                <div class="p-2  flex-fill"><i class="fa fa-money"></i> 人均费用
                    <span render-html="perExpends"></span></div>
            </div>
            <div class="d-flex">
                <div class="p-2  flex-fill">
                    <i class="fa fa-user-circle"></i> 人物
                    <span render-html="personName"></span>
                </div>
                <div class="p-2  flex-fill"><i class="fa fa-clock-o"></i> 出行天数
                    <span render-html="days"></span>
                </div>
            </div>
        </fieldset>

        <div class="content" render-html="travelContent.content">
        </div>
    </div>

    <hr>
    <!--点赞栏-->
    <div class="container d-flex">
        <div class="p-2  flex-fill">
            <i class="fa fa-thumbs-o-up"  id="likeBtn"> </i>
        </div>
        <div class="p-2 flex-fill">
            <!--aria-hidden="true"-->
            <i class="fa fa-user-circle" id="totalCount">
                <span render-html="count"></span>
            </i>
        </div>
        <div class="p-2  flex-fill"><i class="fa  fa-commenting-o"  id="commentBtn"> </i>
        </div>
        <div class="p-2  flex-fill"><i class="fa fa-star-o" id="collectBtn"> </i>
        </div>
    </div>


</div>



</body>

</html>